package com.examination.system.administrator.controller;

import com.examination.api.administrator.DepartmentControllerApi;
import com.examination.framework.model.response.QueryResponseResult;
import com.examination.framework.model.response.ResponseResult;
import com.examination.system.administration.Department;
import com.examination.system.administration.response.AddAdministrationResult;
import com.examination.system.administration.response.DeleteAdministrationResult;
import com.examination.system.administrator.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author 寇淇芮
 * @Date 2019/9/14 9:46
 */
@RestController
@RequestMapping("/administrator/department")
public class DepartmentController implements DepartmentControllerApi {

    @Autowired
    DepartmentService departmentService;

    @Override
    @PostMapping("/add")
    public AddAdministrationResult addDepartment(@RequestBody Department department) {
        return departmentService.addDepartment(department);
    }

    @Override
    @DeleteMapping("/delete/{departmentId}/{newDepartmentName}")
    public DeleteAdministrationResult deleteDepartmentById(@PathVariable(value = "departmentId") String departmentId,
                                                           @PathVariable(value = "newDepartmentName") String newDepartmentName,
                                                           @RequestBody(required = false) Department department) {
        return departmentService.deleteDepartmentById(departmentId,newDepartmentName,department);
    }

    @Override
    @PutMapping("/upate/{departmentId}")
    public ResponseResult editDepartmentById(@PathVariable(value = "departmentId") String departmentId,
                                             @RequestBody Department department) {
        return departmentService.editDepartmentById(departmentId,department);
    }

    @Override
    @GetMapping("/list/{page}/{size}")
    public QueryResponseResult findDepartmentList(@PathVariable(value = "page") Integer page,
                                                  @PathVariable(value = "size") Integer size,
                                                  @RequestBody(required = false) Department department) {
        return departmentService.findDepartmentList(page,size,department);
    }

    @Override
    @GetMapping("/list")
    public QueryResponseResult findDepartmentList() {
        return departmentService.findDepartmentList();
    }

}
